package com.ybkj.daijia.server.sales;

import com.ybkj.daijia.server.model.Base;
import com.ybkj.daijia.server.model.Company;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 优惠劵规则
 *
 * @author Shine
 */
public class CouponRule extends Base {

    public static final int COUPONRULE_STATUS_NOTSTART = 0;
    public static final int COUPONRULE_STATUS_ONUSING = 1;
    public static final int COUPONRULE_STATUS_OVERDUE = 2;
    public static final int TYPE_DISCOUNT = 0;//打折
    public static final int TYPE_DEDUCTION = 1;//抵扣(减法)
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private String title;//优惠券简介

    private String code;//编码

    private Date start;// 开始时间

    private Date end;//结束时间

    private Long companyId;

    private BigDecimal money;//抵扣金额

    private boolean lapsed;//是否失效

    private List<Coupon> coupons;

    private Company company;

    private Integer type;//优惠券类型 0打折 1抵扣

    private CouponType couponType;//服务类型

    private Double discount;//打折优惠券

    private Integer number;//优惠券数量

    private Integer eachLimit;//每人限领：0为不限制

    private Long couponTypeId;//服务类型id(couponType为跑腿则是跑腿类型id)

    private String couponTypeName; //临时字段

    public String getCouponTypeName() {

        return couponTypeName;
    }


    public void setCouponTypeName(String couponTypeName) {

        this.couponTypeName = couponTypeName;
    }


    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public BigDecimal getMoney() {
        if (null == money) {
            return BigDecimal.ZERO;
        }
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public Integer getEachLimit() {
        return eachLimit;
    }

    public void setEachLimit(Integer eachLimit) {
        this.eachLimit = eachLimit;
    }

    public Long getCouponTypeId() {
        return couponTypeId;
    }

    public void setCouponTypeId(Long couponTypeId) {
        this.couponTypeId = couponTypeId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    public boolean isLapsed() {
        return lapsed;
    }

    public void setLapsed(boolean lapsed) {
        this.lapsed = lapsed;
    }

    public List<Coupon> getCoupons() {
        return coupons;
    }

    public void setCoupons(List<Coupon> coupons) {
        this.coupons = coupons;
    }

    public Integer getTimeStatus() {
        if (start.getTime() > System.currentTimeMillis()) {
            return COUPONRULE_STATUS_NOTSTART;
        } else if (null != end && end.getTime() < System.currentTimeMillis()) {
            return COUPONRULE_STATUS_OVERDUE;
        } else {
            return COUPONRULE_STATUS_ONUSING;
        }
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    public CouponType getCouponType() {
        return couponType;
    }

    public void setCouponType(CouponType couponType) {
        this.couponType = couponType;
    }


    public enum CouponType {
        /**
         * 代驾
         */
        daijia,
        /**
         * 专车
         */
        zhuanche,
        /**
         * 跑腿
         */
        paotui,
        /**
         * 货运
         */
        freight,
        /**
         * 洗车
         */
        xiche,
        /**
         * 拼车
         */
        pinche,
        /**
         * 专线
         */
        zhuanxian,
        /**
         * 加油站
         */
        gasstation,
        /**
         * 全部
         */
        all

    }

}
